package com.ssy.lingxi.enhance.controller.process;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.enhance.api.model.dto.AddLogisticsDTO;
import com.ssy.lingxi.enhance.api.model.dto.ConfirmLogisticsDTO;
import com.ssy.lingxi.enhance.constant.RoleTypeEnum;
import com.ssy.lingxi.enhance.model.dto.CommonIdDTO;
import com.ssy.lingxi.enhance.model.qo.ProduceNoticeOrderQO;
import com.ssy.lingxi.enhance.model.vo.ProduceNoticeOrderDetailsVO;
import com.ssy.lingxi.enhance.model.vo.ProduceNoticeOrderListVO;
import com.ssy.lingxi.enhance.service.common.CommonService;
import com.ssy.lingxi.enhance.service.process.ProcessToBeAddLogisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @menu 加工能力 - 确认生产通知单(加工企业) - 待新增物流单
 * @author fhj
 * @version 2.0.0
 * @date 2020/10/20
 */
@Api(tags = "加工能力 - 确认生产通知单(加工企业) - 待新增物流单")
@RestController
@RequestMapping("/enhance/process/toBeAddLogistics")
public class ProcessToBeAddLogisticsController extends BaseController {

    @Resource
    private ProcessToBeAddLogisticsService toBeAddLogisticsService;
    @Resource
    private CommonService commonService;

    @ApiOperation(value = "列表")
    @GetMapping(value = "/list")
    public Wrapper<PageData<ProduceNoticeOrderListVO>> list(@Valid ProduceNoticeOrderQO qo) {
        return toBeAddLogisticsService.list(qo, getSysUser());
    }

    @ApiOperation(value = "详情")
    @GetMapping(value = "/details")
    public Wrapper<ProduceNoticeOrderDetailsVO> details(@Valid CommonIdDTO dto) {
        return commonService.details(dto.getId(), RoleTypeEnum.PROCESS.getCode(), getSysUser());
    }

    @ApiOperation(value = "内部接口：提交物流单")
    @PostMapping(value = "/submit")
    public Wrapper<Void> submit(@RequestBody @Valid AddLogisticsDTO dto) {
        return toBeAddLogisticsService.submit(dto);
    }

    /**
     * 当生产通知单新增了物流单之后, 物流商那边需要确认物流单, 可以接受或不接受。不接受的话需要加工企业修改物流单重新由物流商来确认。
     * */
    @ApiOperation(value = "内部接口：确认物流单")
    @PostMapping(value = "/confirmLogistics")
    public Wrapper<Void> confirmLogistics(@RequestBody @Valid ConfirmLogisticsDTO dto) {
        return toBeAddLogisticsService.confirmLogistics(dto);
    }
}
